package com.zy.control;

import com.zy.entity.Book;
import com.zy.entity.Person;
import io.swagger.annotations.*;
import org.springframework.util.MimeTypeUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(value = "/api", description = "主要用于书籍操作",tags = "书籍管理相关接口")
@RequestMapping("/api")
public class BookController {

    @GetMapping("/v1/books/{bid}")
    @ApiOperation(value = "查询所有书籍中某一本", notes = "调用方：", produces = MimeTypeUtils.APPLICATION_JSON_VALUE, httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "书籍主键ID", name = "bid", required = true, paramType = "path", dataType = "string")
    })
    public Book getBook(@PathVariable String bid) {
        return new Book(bid+"","从入门到放弃");
    }


    @PostMapping("/v1/books")
    @ApiOperation(value = "添加书籍", notes = "添加新的书籍",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "书籍主键ID", name = "bid", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(value = "书名", name = "bName", required = true, paramType = "query", dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",response=Book.class),
            @ApiResponse(code=400,message="用户输入错误",response=Book.class),
            @ApiResponse(code=500,message="系统内部错误",response=Book.class)
    })
    public Book saveBook(@RequestParam String  bid, @RequestParam String  bName) {
        return  new Book(bid,bName);
    }

    @PutMapping("/v1/books/{bid}")
    @ApiOperation(value = "查询所有书籍中某一本", notes = "修改一本书", produces = MimeTypeUtils.APPLICATION_JSON_VALUE, httpMethod = "PUT")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "书籍主键ID", name = "bid", required = true, paramType = "path", dataType = "string"),
            @ApiImplicitParam(value = "书实体信息", name = "book", required = true, paramType = "body", dataType = "Book")
    })
    public Book updateBook(@PathVariable String bid, @RequestBody Book book) {
        return book;
    }

    @DeleteMapping("/v1/books/{bid}")
    @ApiOperation(value = "删除书", notes = "删除一本书", produces = MimeTypeUtils.APPLICATION_JSON_VALUE, httpMethod = "DELETE")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "书籍主键ID", name = "bid", required = true, paramType = "path", dataType = "string")
    })
    public String deleteBook(@PathVariable String bid) {
        return "删除成功";
    }


}